Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
web3-core-subscriptions
Advanced tools
Manages web3 subscriptions. This is an internal package.
The web3-core-subscriptions package is part of the Web3.js library, which is used to interact with the Ethereum blockchain. This specific package provides functionality for subscribing to various events and data streams from the Ethereum network, such as new blocks, pending transactions, and logs.
Subscribe to New Blocks
This feature allows you to subscribe to new block headers on the Ethereum blockchain. The provided code sample demonstrates how to set up a subscription to new block headers using Web3.js and how to handle the incoming data.
const Web3 = require('web3');
const web3 = new Web3('wss://mainnet.infura.io/ws/v3/YOUR_INFURA_PROJECT_ID');
const subscription = web3.eth.subscribe('newBlockHeaders', (error, result) => {
if (!error) {
console.log(result);
return;
}
console.error(error);
});
// To unsubscribe
subscription.unsubscribe((error, success) => {
if (success) {
console.log('Successfully unsubscribed!');
}
});
Subscribe to Pending Transactions
This feature allows you to subscribe to pending transactions on the Ethereum network. The code sample shows how to set up a subscription to pending transactions and handle the incoming transaction hashes.
const Web3 = require('web3');
const web3 = new Web3('wss://mainnet.infura.io/ws/v3/YOUR_INFURA_PROJECT_ID');
const subscription = web3.eth.subscribe('pendingTransactions', (error, result) => {
if (!error) {
console.log(result);
return;
}
console.error(error);
});
// To unsubscribe
subscription.unsubscribe((error, success) => {
if (success) {
console.log('Successfully unsubscribed!');
}
});
Subscribe to Logs
This feature allows you to subscribe to logs (events) from smart contracts on the Ethereum blockchain. The code sample demonstrates how to set up a subscription to logs with specific options such as contract address and topics.
const Web3 = require('web3');
const web3 = new Web3('wss://mainnet.infura.io/ws/v3/YOUR_INFURA_PROJECT_ID');
const options = {
address: '0x123456...', // Address of the contract
topics: ['0x123456...'] // Topics to subscribe to
};
const subscription = web3.eth.subscribe('logs', options, (error, result) => {
if (!error) {
console.log(result);
return;
}
console.error(error);
});
// To unsubscribe
subscription.unsubscribe((error, success) => {
if (success) {
console.log('Successfully unsubscribed!');
}
});
The ethers.js library is a complete and compact library for interacting with the Ethereum blockchain and its ecosystem. It provides similar subscription functionalities through its Provider API, allowing users to listen for new blocks, pending transactions, and logs. Compared to web3-core-subscriptions, ethers.js is known for its smaller size and ease of use.
Ethjs is a highly modular and lightweight library for interacting with the Ethereum blockchain. It offers similar subscription capabilities through its EthFilter API, allowing users to subscribe to new blocks, pending transactions, and logs. Ethjs is designed to be minimalistic and efficient, making it a good alternative to web3-core-subscriptions for developers looking for a more lightweight solution.
The web3-providers-ws package is another part of the Web3.js library that specifically deals with WebSocket providers. It can be used in conjunction with web3-core-subscriptions to set up WebSocket connections and manage subscriptions. While it does not provide subscription functionalities on its own, it is an essential component for enabling WebSocket-based subscriptions in Web3.js.
This is a sub-package of web3.js
This subscriptions package is used within some web3.js packages.
Please read the documentation for more.
You can install the package either using NPM or using Yarn
npm install web3-core-subscriptions
yarn add web3-core-subscriptions
const Web3Subscriptions = require('web3-core-subscriptions');
const sub = new Web3Subscriptions({
name: 'subscribe',
type: 'eth',
subscriptions: {
'newBlockHeaders': {
subscriptionName: 'newHeads',
params: 0,
outputFormatter: formatters.outputBlockFormatter
},
'pendingTransactions': {
params: 0,
outputFormatter: formatters.outputTransactionFormatter
}
}
});
sub.attachToObject(myCoolLib);
myCoolLib.subscribe('newBlockHeaders', function(){ ... });
FAQs
Manages web3 subscriptions. This is an internal package.
The npm package web3-core-subscriptions receives a total of 123,889 weekly downloads. As such, web3-core-subscriptions popularity was classified as popular.
We found that web3-core-subscriptions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.